package com.sgcc.sx.pmos.common.adapter;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.sgcc.pmos.nativesdk.R;
import com.sgcc.sx.pmos.common.bean.StoreScreenBean;

import java.util.List;


public class GoodScreenAdapter extends BaseQuickAdapter<StoreScreenBean, BaseViewHolder> {

    public GoodScreenAdapter(List<StoreScreenBean> list) {
        super(R.layout.item_good_screen, list);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, StoreScreenBean s) {
        baseViewHolder.setText(R.id.tvTitle, s.getTitle());
        RecyclerView rvItemList = baseViewHolder.getView(R.id.rvItemList);
        rvItemList.setLayoutManager(new GridLayoutManager(getContext(), 3));
        GoodScreenItemAdapter goodScreenItemAdapter = new GoodScreenItemAdapter(s.getList());
        rvItemList.setAdapter(goodScreenItemAdapter);

        goodScreenItemAdapter.setOnItemClickListener((adapter, view, position) -> {
            List<StoreScreenBean.GoodScreenItemBean> data = goodScreenItemAdapter.getData();
            for (int i = 0; i < data.size(); i++) {
                data.get(i).setSelect(i == position);
            }
            goodScreenItemAdapter.notifyDataSetChanged();
        });


    }
}
